#!/usr/bin/perl
#
# Set the same variable to the same value on every
# base station.  Arguments are the same as
# "snmpset".
#
# This is kind of cheesy, since we have a perl SNMP
# but we want to reuse the command-line parser
# of "snmpset" so we cheese out.
#
# $Id$
#

# I hate arg parsing.  There's got to be a better way than
# using a vintage-1992 .pl .
require 'getopt.pl';

do Getopt('g');
$which = $opt_g || "all";

open(APLIST, "aplist") || die "aplist: $!\n";
while (<APLIST>) {
	chop;
	next if (/^#/ || /^\s*$/);
	($ap, $readcommunity, $writecommunity, $group) = split(/\t/);
	if ($ap eq "write") {
		$defcomm = $readcommunity;
		next;
	}
	next if ($ap eq "default");
	push(@aplist, $ap);
	$community{$ap} = $writecommunity || $defcomm;
	$group{$ap} = $group || "default";
}
close(APLIST);

# make sure the orinoco-mib is in scope
$ENV{'MIBS'}='./orinoco.mib';

$args = join(" ", @ARGV);
print "Setting $args on $which access points...\n";
foreach $ap (@aplist) {
	next if ($which ne "all" && $which ne $group{$ap});
	print "$ap: ";
	system("snmpset -OS $ap $community{$ap} $args");
}
